package com.ruoyi.project.WebMoudle.terraceDetail.controller;

import java.math.BigDecimal;
import java.util.List;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.project.WebMoudle.wxOrder.domain.MoneySum;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.WebMoudle.terraceDetail.domain.TerraceDetail;
import com.ruoyi.project.WebMoudle.terraceDetail.service.ITerraceDetailService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 平台账单Controller
 * 
 * @author ruoyi
 * @date 2020-09-12
 */
@Controller
@RequestMapping("/terraceDetail/terraceDetail")
public class TerraceDetailController extends BaseController
{
    private String prefix = "terraceDetail/terraceDetail";

    @Autowired
    private ITerraceDetailService terraceDetailService;

    @RequiresPermissions("terraceDetail:terraceDetail:view")
    @GetMapping()
    public String terraceDetail()
    {
        return prefix + "/terraceDetail";
    }

    /**
     * 查询平台账单列表
     */
    @RequiresPermissions("terraceDetail:terraceDetail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TerraceDetail terraceDetail)
    {
        startPage();
        List<TerraceDetail> list = terraceDetailService.selectTerraceDetailList(terraceDetail);
        BigDecimal detailSum = terraceDetailService.queryDetailSum(terraceDetail);
        if (!StringUtils.isNotNull(detailSum)){
            detailSum= new BigDecimal("0");
        }
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(0);
        rspData.setRows(list);
        rspData.setTotal(new PageInfo(list).getTotal());
        rspData.setDetailSum(detailSum);
        return rspData;
    }

    /**
     * 导出平台账单列表
     */
    @RequiresPermissions("terraceDetail:terraceDetail:export")
    @Log(title = "平台账单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TerraceDetail terraceDetail)
    {
        List<TerraceDetail> list = terraceDetailService.selectTerraceDetailList(terraceDetail);
        ExcelUtil<TerraceDetail> util = new ExcelUtil<TerraceDetail>(TerraceDetail.class);
        return util.exportExcel(list, "terraceDetail");
    }

    /**
     * 新增平台账单
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存平台账单
     */
    @RequiresPermissions("terraceDetail:terraceDetail:add")
    @Log(title = "平台账单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TerraceDetail terraceDetail)
    {
        return toAjax(terraceDetailService.insertTerraceDetail(terraceDetail));
    }

    /**
     * 修改平台账单
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TerraceDetail terraceDetail = terraceDetailService.selectTerraceDetailById(id);
        mmap.put("terraceDetail", terraceDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存平台账单
     */
    @RequiresPermissions("terraceDetail:terraceDetail:edit")
    @Log(title = "平台账单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TerraceDetail terraceDetail)
    {
        return toAjax(terraceDetailService.updateTerraceDetail(terraceDetail));
    }

    /**
     * 删除平台账单
     */
    @RequiresPermissions("terraceDetail:terraceDetail:remove")
    @Log(title = "平台账单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(terraceDetailService.deleteTerraceDetailByIds(ids));
    }
}
